#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution{
    public:
    int ans1(vector<vector<int>>& points){
        vector<vector<int>> ret;
        sort(points.begin(), points.end());
        for(int i = 0; i != points.size(); i++){
            int L = points[i][0], R = points[i][1];
            if(!ret.size() || ret.back()[1] < L){
                ret.push_back({L, R});
            }else{
                ret.back()[0] = max(ret.back()[0], L);
                ret.back()[1] = min(ret.back()[1], R);
            }
        }
        return ret.size();
    }

};

void test1(){
    Solution s;
    vector<vector<int>> nums = {{10,16}, {2,8}, {1,6}, {7,12}};
    int ret = s.ans1(nums);
    cout << ret << endl;
}

void test2(){
    Solution s;
    vector<vector<int>> nums = {{1,2}, {3,4}, {5,6}, {7,8}};
    int ret = s.ans1(nums);
    cout << ret << endl;
}

void test3(){
    Solution s;
    vector<vector<int>> nums = {{1,2}, {2,3}, {3,4}, {4,5}};
    int ret = s.ans1(nums);
    cout << ret << endl;
}


int main(void){
    test1();
    test2();
    test3();

    return 0;
}